<template>
  <a-row :gutter="24">
    <a-col :md="4" :sm="24">
      <a-card :bordered="false" :loading="treeLoading">
        <a-directory-tree
          :showIcon="false"
          :treeData="treeList"
          v-if="treeList.length"
          @select="handleClick"
          :defaultExpandAll="true"
        />
      </a-card>
    </a-col>

    <a-col :md="19" :sm="24">
      <a-card :bordered="false" v-show="gatewayId!==0">
        <div class="table-page-search-wrapper">
          <a-form :form="form">
            <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '0px', paddingLeft: '16px'}">
              <a-tab-pane loading="true" tab="基本配置" key="1" style="margin-top: 35px">
                <a-col
                  :span="12"
                  v-show="!!setData.micDeviceType">
                  <a-form-item
                    :span="12"
                    label="采集数据模式"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group v-decorator="['micDeviceType']">
                      <a-radio value="tcp">tcp</a-radio>
                      <a-radio value="ftp">ftp</a-radio>
                      <a-radio value="usb">usb</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.micUsbMode">
                  <a-form-item
                    label="是否有1：N过程"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['micUsbMode',{ initialValue: '2' }]">
                      <a-radio value="1">有1：N过程</a-radio>
                      <a-radio value="2">无1：N过程</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.micUsbModeChannelNum">
                  <a-form-item
                    label="usb模式通道数"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['micUsbModeChannelNum']">
                      <a-radio value="1">1</a-radio>
                      <a-radio value="2">2</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.micUploadFileQuantity">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="每小时上传文件个数"
                    v-show="!!setData.micUploadFileQuantity"
                  >
                    <a-input-number
                      placeholder="0"
                      style="width: 100%"
                      v-decorator="['micUploadFileQuantity', { initialValue: '0' }]"
                      :min="0"
                      :max="100"
                      :step="1"/>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.micDeviceName">
                  <a-form-item
                    label="USB模式声卡名称"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入USB模式声卡名称"
                      v-decorator="['micDeviceName']"/>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.audioWavSize">
                  <a-form-item
                    label="文件大小"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-select
                      style="width: 100%"
                      v-decorator="['audioWavSize']"
                      allow-clear
                      placeholder="请选择文件大小">
                      <a-select-option v-for="(item,ind) in audioWavSizeList" :key="ind" :value="item.value">{{ item.key }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.audioTmpSavePath">
                  <a-form-item
                    label="临时文件目录"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入临时文件目录"
                      v-decorator="['audioTmpSavePath']"/>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.audioBackupPath">
                  <a-form-item
                    label="备份文件目录"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入备份文件目录"
                      v-decorator="['audioBackupPath']"/>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.appNetworkInterface">
                  <a-form-item
                    label="发送网卡IP"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入发送网卡IP"
                      v-decorator="['appNetworkInterface']"/>
                  </a-form-item>
                </a-col>

                <a-col
                  :span="12"
                  v-show="!!setData.appReportStartupStatus">
                  <a-form-item
                    label="发送设备CPU温度"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['appReportStartupStatus']">
                      <a-radio value="on">开</a-radio>
                      <a-radio value="off">关</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.appUploadTemperatureOnOff">
                  <a-form-item
                    label="发送启动日志信息"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['appUploadTemperatureOnOff']">
                      <a-radio value="on">开</a-radio>
                      <a-radio value="off">关</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.reportFlowOnOff">
                  <a-form-item
                    label="发送流量信息"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['reportFlowOnOff']">
                      <a-radio value="on">开</a-radio>
                      <a-radio value="off">关</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
              </a-tab-pane>
              <!-- 高级配置 -->
              <a-tab-pane tab="高级配置" :forceRender="true" key="2" style="margin-top: 35px">
                <a-col
                  :span="12"
                  v-show="!!setData.micGroupId">
                  <a-form-item
                    label="算法分组号"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入算法分组号"
                      v-decorator="['micGroupId']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micAccessToken">
                  <a-form-item
                    label="算法ID"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入算法ID"
                      v-decorator="['micAccessToken']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micRouterBase">
                  <a-form-item
                    label="通道号生成基础数"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input-number
                      placeholder="通道号生成基础数"
                      style="width: 100%"
                      v-decorator="['micRouterBase']"
                      :min="0"
                      :max="7"
                      :step="1"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micIsShieldDefaultDevice">
                  <a-form-item
                    label="USB模式是否屏蔽default设备"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['micIsShieldDefaultDevice']">
                      <a-radio value="true">是</a-radio>
                      <a-radio value="false">否</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micTcpIp">
                  <a-form-item
                    label="TCP模式下IP地址"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入TCP模式下IP地址"
                      v-decorator="['micTcpIp']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micTcpPort">
                  <a-form-item
                    label="TCP模式下端口号"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input-number
                      placeholder="端口号"
                      style="width: 100%"
                      v-decorator="['micTcpPort']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micDiskCapacity">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="存储剩余大小(%)"
                  >
                    <a-input-number
                      placeholder="95"
                      style="width: 100%"
                      v-decorator="['micDiskCapacity', { initialValue: '95' }]"
                      :min="5"
                      :max="100"
                      :step="5"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micFileStorageMode">
                  <a-form-item
                    label="文件存储模式"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['micFileStorageMode',{ initialValue: 'local' }]">
                      <a-radio value="local">本地</a-radio>
                      <a-radio value="remote">远程</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micMaxFrequencyVoiceRatio">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="音频过载判断比例(%)"
                  >
                    <a-input-number
                      placeholder="80"
                      style="width: 100%"
                      v-decorator="['micMaxFrequencyVoiceRatio', { initialValue: '80' }]"
                      :min="10"
                      :max="100"
                      :step="10"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micNoFrequencyVoiceRatio">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="音频无声判断比例(%)"
                  >
                    <a-input-number
                      placeholder="20"
                      style="width: 100%"
                      v-decorator="['micNoFrequencyVoiceRatio', { initialValue: '20' }]"
                      :min="10"
                      :max="100"
                      :step="10"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.micFileErrorIsDelete">
                  <a-form-item
                    label="文件无声或过载是否删除文件"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['micFileErrorIsDelete',{ initialValue: 'true' }]">
                      <a-radio value="true">是</a-radio>
                      <a-radio value="false">否</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.audioScanPath">
                  <a-form-item
                    label="FTP文件扫描路径扫描路径"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="FTP文件扫描路径扫描路径"
                      v-decorator="['audioScanPath']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.engineHttpUrl">
                  <a-form-item
                    label="引擎地址"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="引擎地址"
                      v-decorator="['engineHttpUrl']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.engineFileSaveUrl">
                  <a-form-item
                    label="文件存储服务器地址"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="文件存储服务器地址"
                      v-decorator="['engineFileSaveUrl']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.sensorOnOrOff">
                  <a-form-item
                    label="是否启用倾角设备"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['sensorOnOrOff',{ initialValue: 'off' }]">
                      <a-radio value="on">是</a-radio>
                      <a-radio value="off">否</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.sensorSerialCom">
                  <a-form-item
                    label="倾角传感器串口号"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="倾角传感器串口号"
                      v-decorator="['sensorSerialCom']"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.sensorSensorSampleRate">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="传感器采集速率(ms)"
                  >
                    <a-input-number
                      placeholder="1000"
                      style="width: 100%"
                      v-decorator="['sensorSensorSampleRate', { initialValue: '1000' }]"
                      :min="1000"
                      :step="1000"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.audiocaptureOnOrOff">
                  <a-form-item
                    label="8路采集板串口控制开关"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['audiocaptureOnOrOff']">
                      <a-radio value="on">开</a-radio>
                      <a-radio value="off">关</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.audiocaptureSerialName">
                  <a-form-item
                    label="8路采集板串口名称"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="8路采集板串口名称"
                      v-decorator="['audiocaptureSerialName',{ initialValue: 'ttyXRUSB0' }]"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.sensorSensorSampleRate">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="8路采集板录音时间"
                  >
                    <a-input-number
                      style="width: 100%"
                      v-decorator="['sensorSensorSampleRate']"
                      :min="7"
                      :max="35"
                      :step="1"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.soundmakerOnOrOff">
                  <a-form-item
                    label="主动发声开关"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-radio-group
                      v-decorator="['soundmakerOnOrOff']">
                      <a-radio value="on">开</a-radio>
                      <a-radio value="off">关</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.soundmakerFrequency">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="主动发声频率"
                  >
                    <a-input-number
                      style="width: 100%"
                      v-decorator="['soundmakerFrequency']"
                      :min="50"
                      :max="20000"
                      :step="50"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.audiocaptureRecordingTime">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="8路采集板录音时间"
                  >
                    <a-input-number
                      placeholder="15"
                      style="width: 100%"
                      v-decorator="['audiocaptureRecordingTime']"
                      :min="7"
                      :max="30"
                      :step="1"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.soundmakerVolumeActiveVoice">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="主动发声音量"
                  >
                    <a-input-number
                      placeholder="10"
                      style="width: 100%"
                      v-decorator="['soundmakerVolumeActiveVoice', { initialValue: '10' }]"
                      :min="1"
                      :max="10"
                      :step="1"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.soundmakerWorkingTime">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="主动发声工作时间(s)"
                  >
                    <a-input-number
                      placeholder="10"
                      style="width: 100%"
                      v-decorator="['soundmakerWorkingTime', { initialValue: '10' }]"
                      :min="7"
                      :max="30"
                      :step="1"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.soundmakerIntermittentTime">
                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="主动发声间隔时间(s)"
                  >
                    <a-input-number
                      placeholder="60"
                      style="width: 100%"
                      v-decorator="['soundmakerIntermittentTime', { initialValue: '60' }]"
                      :min="0"
                      :step="1"/>
                  </a-form-item>
                </a-col>
                <a-col
                  :span="12"
                  v-show="!!setData.soundmakerPlayVoiceDeviceName">
                  <a-form-item
                    label="主动发声设备名称"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入主动发声设备名称"
                      v-decorator="['soundmakerPlayVoiceDeviceName']"/>
                  </a-form-item>

                  <a-form-item
                    label="光纤服务开关"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalOnOrOff"
                  >
                    <a-radio-group v-decorator="['opticalOnOrOff']">
                      <a-radio value="on">开</a-radio>
                      <a-radio value="off">关</a-radio>
                    </a-radio-group>
                  </a-form-item>

                  <a-form-item
                    label="光纤服务URL"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalServerUrl"
                    has-feedback
                  >
                    <a-input
                      placeholder="请输入光纤服务URL（http://ip:port/）"
                      v-decorator="['opticalServerUrl',{ initialValue: 'http://192.168.1.2:8000/' }]"/>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalVibrationPort"
                    label="光纤振动数据采集服务端口"
                  >
                    <a-input-number
                      placeholder="60"
                      style="width: 100%"
                      v-decorator="['opticalVibrationPort', { initialValue: '4070' }]"
                      :min="9000"
                      :step="10250"/>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalAudioPort"
                    label="光纤音频数据采集服务端口"
                  >
                    <a-input-number
                      placeholder="60"
                      style="width: 100%"
                      v-decorator="['opticalAudioPort', { initialValue: '4060' }]"
                      :min="9000"
                      :step="1"/>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalListeningLocation"
                    label="光纤侦听点位"
                  >
                    <a-input-number
                      placeholder="60"
                      style="width: 100%"
                      v-decorator="['opticalListeningLocation', { initialValue: '2745' }]"
                      :min="200"
                      :step="1"/>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalDiff"
                    label="光纤采样率配置"
                  >
                    <a-radio-group v-decorator="['opticalDiff', { initialValue: '100' }]">
                      <a-radio value="40">40</a-radio>
                      <a-radio value="80">80（8k）</a-radio>
                      <a-radio value="100">100（16k）</a-radio>
                    </a-radio-group>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalDistance"
                    label="光纤侦听距离（Km）"
                  >
                    <a-input-number
                      placeholder="60"
                      style="width: 100%"
                      v-decorator="['opticalDistance', { initialValue: '2' }]"
                      :min="1"
                      :step="1"/>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalNoiseReductionLevel"
                    label="光纤降噪等级"
                  >
                    <a-radio-group v-decorator="['opticalNoiseReductionLevel', { initialValue: '2' }]">
                      <a-radio value="1">1级</a-radio>
                      <a-radio value="2">2级</a-radio>
                      <a-radio value="3">3级</a-radio>
                    </a-radio-group>
                  </a-form-item>

                  <a-form-item
                    label="光纤降噪开关"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalNoiseReductionSwitch"
                  >
                    <a-radio-group
                      v-decorator="['opticalNoiseReductionSwitch']">
                      <a-radio value="true">开</a-radio>
                      <a-radio value="false">关</a-radio>
                    </a-radio-group>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalScanRate"
                    label="光纤音频采样率（Hz）"
                  >
                    <a-radio-group v-decorator="['opticalScanRate', { initialValue: '16000' }]">
                      <a-radio value="16000">16000</a-radio>
                      <a-radio value="8000">8000</a-radio>
                    </a-radio-group>
                  </a-form-item>

                  <a-form-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    v-show="!!setData.opticalVibrationThreshold"
                    label="光纤振动数据报警阈值"
                  >
                    <a-input-number
                      placeholder="60"
                      style="width: 100%"
                      v-decorator="['opticalVibrationThreshold', { initialValue: '300' }]"
                      :min="0"
                      :step="1"/>
                  </a-form-item>
                </a-col>
              </a-tab-pane>
            </a-tabs>
          </a-form>
          <a-button @click="handleSubmit" type="button" size="large" class="ant-btn ant-btn-primary" :loading="btnLoading"><span>确 定</span>
          </a-button>
        </div>
      </a-card>
    </a-col>
  </a-row>
</template>

<script>
  import { treeList, getConfig, updateConfig } from '@/api/modular/main/bizgateway/bizGatewayManage'
  export default {
    props: {
      stationId: {
        type: Number,
        require: false
      }
    },
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 14 }
        },
        advanced: false, // 高级搜索 展开/关闭
        defaultExpandedKeys: [],
        replaceFields: {
          key: 'id'
        },
        treeList: [],
        treeLoading: true,
        index: -1,
        micRouterBase: [0, 1, 2, 3, 4, 5, 6, 7],
        micDeviceType: [{ type: 'tcp' }, { type: 'ftb' }, { type: 'usb' }],
        micTcpIp: '',
        micTcpPort: '',
        micUsbMode: [{ model: '有1:N过程', value: 1 }, { model: '无1:N过程', value: 2 }],
        micFileStorageMode: [{ model: '本地' }, { model: '远程' }],
        micUsbModeChannelNum: '',
        audioScanPath: [{ path: '/home/anyone' }],
        audioTmpSavePath: [{ path: '/home/zkhy/tmpFiles' }],
        audioBackupPath: [{ path: '/home/zkhy/backup' }],
        engineHttpUrl: [{ path: 'http://127.0.0.1:8899/' }],
        engineFileSaveUrl: [{ path: 'http://127.0.0.1:8899/' }],
        sensorSerialCom: [{ port: 'com' }, { port: 'tty' }],
        sensorDeviceCode: [{ code: '123456' }],
        audiocaptureOnOrOff: [{ value: 'on' }, { value: 'off' }],
        audiocaptureSerialName: [{ name: 'ttyXRUSB0' }],
        soundmakerOnOrOff: [{ value: 'on' }, { value: 'off' }],
        soundmakerPlayVoiceDeviceName: '',
        appNetworkInterface: [{ ip: '127.0.0.1' }],
        appReportStartupStatus: [{ value: 'on' }, { value: 'off' }],
        appUploadTemperatureOnOff: [{ value: 'on' }, { value: 'off' }],
        uploadNormalStatus: [{ value: 'on' }, { value: 'off' }],
        audioWavSizeList: [{
          key: '7s',
          value: '224046'
        }, {
          key: '10s',
          value: '320046'
        }, {
          key: '15s',
          value: '480046'
        }, {
          key: '30s',
          value: '960046'
        }],
        setData: {},
        queryParam: {},
        form: this.$form.createForm(this),
        gatewayId: 0,
        btnLoading: false
      }
    },

    created () {
      this.queryParam.stationId = this.stationId
      this.getGatewayTree()
    },

    methods: {
      getGatewayTree () {
        treeList(Object.assign(this.queryParam)).then(res => {
          this.treeLoading = false
          if (!res.success) {
            return
          }
          this.treeList = res.data
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      handleClick (e) {
        if (e.length > 0) {
          this.gatewayId = e.toString()
          this.resetValue()
        }
      },
      resetValue () {
        const that = this
        getConfig({
          id: this.gatewayId
        }).then((res) => {
          this.setData = res.data
          const data = res.data
          Object.keys(that.form.getFieldsValue()).forEach(item => {
            const value = data[item]
            that.form.setFieldsValue({ [item]: value })
          })
        })
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        validateFields((errors, values) => {
          this.btnLoading = true
          if (!errors) {
            values.id = this.gatewayId
            updateConfig(values).then((res) => {
              this.confirmLoading = false
              if (res.success) {
                this.$message.success('修改成功')
              } else {
                this.$message.info('修改失败：' + res.message)
              }
            }).finally((res) => {
              this.btnLoading = false
            })
          } else {
            this.btnLoading = false
          }
        })
      },
      handleCancel () {
        this.queryParam = {}
        this.visible = false
      }
    }
  }
</script>

<style lang="less">
  @import '../~@/assets/css/list.less';

  .table-operator {
    margin-bottom: 18px;
  }

  button {
    margin-right: 8px;
  }
</style>
